package com.ruoyi.common.utils;



import lombok.RequiredArgsConstructor;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.springframework.stereotype.Component;

import java.util.*;


@RequiredArgsConstructor
@Component
public class ServiceHelper {

    private final ModelMapper modelMapper;


    public <T> T convertToModel(Object obj, Class<T> t) {
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        return modelMapper.map(obj, t);
    }

    public <D> D convertToDto(Object obj, Class<D> d) {
        modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
        return modelMapper.map(obj, d);
    }


    private Boolean isTagExist(String tagIds, Integer tagId) {
        String[] tags = tagIds.split(",");
        if (tags.length == 0) {
            return tagIds.equals(String.valueOf(tagId));
        }
        return Arrays
                .stream(tags)
                .filter(x -> x.equals(String.valueOf(tagId)))
                .count() > 0;
    }


}
